//
//  ViewController.m
//  Picker Views
//
//  Created by iD Student on 7/1/13.
//  Copyright (c) 2013 iD Student. All rights reserved.
//

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
	// Do any additional setup after loading the view, typically from a nib.
    colorList = [[NSMutableArray alloc] init];
    [colorList addObject:[NSString stringWithString:@"red"]];
    [colorList addObject:[NSString stringWithString:@"blue"]];
    [colorList addObject:[NSString stringWithString:@"green"]];
    
    [colorList addObject:[NSString stringWithString:@"rock"]];
    [colorList addObject:[NSString stringWithString:@"paper"]];
    [colorList addObject:[NSString stringWithString:@"scissors"]];
    
    colorPicker.delegate = self;
    colorPicker.dataSource = self;
    
    appSettings = [NSUserDefaults standardUserDefaults];
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

-(NSInteger)numberOfComponentsInPickerView:(UIPickerView *)thePickerView
{
    return 1;
}
- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component
{
    // The count of items in the array colorList.
    return colorList.count;
}
-(NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component
{
    return [colorList objectAtIndex:row];
}
-(void)pickerView:(UIPickerView *)thePickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
{
    selectedRow = row;
    [appSettings setInteger:selectedRow forKey:@"selectedRow"];
    [appSettings synchronize];
    
}
-( IBAction)changePressed:(id)sender
{
    NSString *selectedColor = [colorList objectAtIndex:selectedRow];
    if([selectedColor compare:@"red"] == NSOrderedSame)
    {
        [self.view setBackgroundColor:[UIColor redColor]];
    }
    if([selectedColor compare:@"blue"] == NSOrderedSame)
    {
        [self.view setBackgroundColor:[UIColor blueColor]];
    }
    if([selectedColor compare:@"green"] == NSOrderedSame)
    {
        [self.view setBackgroundColor:[UIColor greenColor]];
    }
    
    MainViewController *viewController;
    //[viewController performSelector:@selector(setup) withObject:[colorList objectAtIndex:selectedRow]];
   // [self performSegueWithIdentifier:@"segue" sender:self];
}

@end
